//
//  BrowseBottomView.m
//  jinnengExam
//
//  Created by mac on 2020/8/13.
//  Copyright © 2020 jznrj. All rights reserved.
//

#import "BrowseBottomView.h"
#import <Masonry.h>
@implementation BrowseBottomView

- (id)init
{
    self = [super init];
    if (!self) {
        return nil;
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (!self) {
        return nil;
    }
    return self;
}
-(void)setupView{
        // Initialization code
        self.previewButton = [[CustomMenuButton alloc] init];
        [self addSubview:self.previewButton];
        [self.previewButton  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(self).multipliedBy(0.3);
            make.height.mas_equalTo(self.mas_height);
            make.left.top.equalTo(self);
        }];
        self.previewButton.tag = 100;
        [self.previewButton setButtonInfo:@{@"title":@"上一题", @"icon":@"icon_preview",@"highlightIcon":@"icon_preview_pressed"}];
        [self.previewButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    
       self.nextButton = [[CustomMenuButton alloc] init];
      [self addSubview:self.nextButton];
      [self.nextButton  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(self).multipliedBy(0.3);
            make.height.mas_equalTo(self.mas_height);
            make.centerX.top.equalTo(self);
        }];
        self.nextButton.tag = 101;
        [self.nextButton setButtonInfo:@{@"title":@"下一题", @"icon":@"icon_next",@"highlightIcon":@"icon_next_pressed"}];
        [self.nextButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  
        
        self.showResultButton = [[CustomMenuButton alloc] init];
        [self addSubview:self.showResultButton];
        [self.showResultButton  mas_makeConstraints:^(MASConstraintMaker *make) {
              make.width.equalTo(self).multipliedBy(0.3);
              make.height.mas_equalTo(self.mas_height);
              make.right.top.equalTo(self);
        }];
        self.showResultButton.tag = 104;
        [self.showResultButton setButtonInfo:@{@"title":@"显示答案", @"icon":@"icon_hide_answer",@"highlightIcon":@"icon_hide_answer_pressed"}];
        [self.showResultButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    
        self.hideResultButton = [[CustomMenuButton alloc] init];
        self.hideResultButton.hidden = YES;
        [self addSubview:self.hideResultButton];
        [self.hideResultButton  mas_makeConstraints:^(MASConstraintMaker *make) {
              make.width.equalTo(self).multipliedBy(0.3);
              make.height.mas_equalTo(self.mas_height);
              make.right.top.equalTo(self);
        }];
        self.hideResultButton.tag = 105;
        [self.hideResultButton setButtonInfo:@{@"title":@"隐藏答案", @"icon":@"icon_show_answer",@"highlightIcon":@"icon_show_answer_pressed"}];
        [self.hideResultButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

        self.userInteractionEnabled = YES;
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect
 {
 // Drawing code
 }
 */
- (void)buttonAction:(id)sender
{
    if (self.delegate == nil) {
        return;
    }
    UIButton *button = (UIButton *)sender;
    NSInteger tag = button.tag;
    if (tag == 100) { // 上一题
        [self.delegate onButtonAction:0];
    }
    else if (tag == 101) { // 下一题
        [self.delegate onButtonAction:1];
    }
    else if (tag == 104) { // 显示答案
        [self.delegate onButtonAction:2];
    }
    else if (tag == 105) { // 显示答案
        [self.delegate onButtonAction:3];
    }
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
